package cn.mrlong.idcardphoto;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import cn.mrlong.idcardphoto.camera.CameraActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = findViewById(R.id.tv);
        Button btn = findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //设置存储路径
                CameraActivity.setPath(Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/AlinkIdCard");
                CameraActivity.openCamera(MainActivity.this, CameraActivity.IDCARD_BACK);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CameraActivity.REQ_CODE && resultCode == CameraActivity.RES_CODE) {
            //获取图片路径，显示图片
            final String path = CameraActivity.getImagePath(data);
            tv.setText(path);
//            if (!TextUtils.isEmpty(path)) {
//                imageView.setImageBitmap(BitmapFactory.decodeFile(path));
//                dataStr = bitmapToBase64(BitmapFactory.decodeFile(path));
//
//                System.out.println("====================>2" + dataStr.length());
//            }
//
//            System.out.println("====================>1" + encodeBase64File(path).length());
        }
    }
}
